<?php 
switch($_REQUEST['gruppo']){
	case 2:
		$table = "alunni";
		$id_name = "id_alunno";
		break;
	case 3:
		$table = "genitori";
		$id_name = "id_genitore";
		break;
	case 1:
	default:
		$table = "utenti";
		$id_name = "uid";
		break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="" />
<link rel="stylesheet" href="../css/main.css" type="text/css" />
<script type="text/javascript" src="../js/prototype.js"></script>
<script type="text/javascript" src="../js/scriptaculous.js"></script>
<script type="text/javascript" src="../js/controls.js"></script>
<script type="text/javascript" src="../js/page.js"></script>
<script type="text/javascript">
function registra(){
	var patt = /[^a-zA-Z0-9]/;
	if(trim(document.forms[0].n_pwd.value) == ""){
		alert("Password non valida.");
		return false;
	}
	else if(document.forms[0].n_pwd.value.match(patt)){
		alert("Password non valida: sono ammessi solo lettere e numeri");
		return false;
	}
	if(trim(document.forms[0].n_pwd.value) != trim(document.forms[0].n_pwd2.value)){
		alert("Le password inserite sono differenti. Ricontrolla.");
		return false;
	}
	p = hex_md5(document.forms[0].n_pwd.value);
	// fake password
	document.forms[0].n_pwd2.value = "calatafimi";
	var url = "adm_pwd_changer.php";
	var req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: {n_p: p, table: '<?php print $table ?>', campo: '<?php print $id_name ?>', uid: <?php print $_REQUEST['uid'] ?>, p2: document.forms[0].n_pwd.value},
			    	onSuccess: function(transport){
			    		var response = transport.responseText || "no response text";
			    		dati = response.split(";");
			      		if(dati[0] == "ko"){
			      			//alert("Password non modificata\n"+dati[1]+"\n"+dati[2]);
			      			parent.msg = "Password non modificata\n"+dati[1]+"\n"+dati[2];
			      			parent.openInfoDialog();
			            	parent.win.close();
			                return;
			     		}
			     		else{
			     			parent.msg = "Password modificata correttamente";
			     			parent.openInfoDialog();
			            	parent.win.close();
			     		}
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore..."); }
			  });
}

</script>
</head>
<body>
<p style="font-size: 12px; font-weight: bold; text-align: center; margin-top: 5px">Modifica password di <?php print $_GET['ut'] ?></p>
<form>
<div style="margin-right: auto; margin-left: auto; margin-top: 40px; width: 350px">
<div style='font-weight: bold; font-size: 11px; text-align: left; margin-top: 20px; margin-left: 15px' class='popup_title'>Nuova password<input style='width: 180px; float: right; margin-right: 20px' type='password' name='n_pwd' id='n_pwd' /></div>
<div style='font-weight: bold; font-size: 11px; text-align: left; margin-top: 20px; margin-left: 15px' class='popup_title'>Reinserisci<input style='width: 180px; float: right; margin-right: 20px' type='password' name='n_pwd2' /></div>
<div style='font-weight: bold; font-size: 11px; text-align: right; margin-top: 20px; margin-right: 20px; margin-bottom: 20px' class='Titolo'>
	<a href="#" onclick='registra()' style="font-weight: normal">Registra</a>&nbsp;&nbsp;|&nbsp;&nbsp;
	<a href="#" onclick="window.close()" style="font-weight: normal">Chiudi</a>
</div>
</div>
</form>
</body>
</html>